<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>Promise发生AJAX请求</title>
	</head>
	<body>
		<script>
			const p = new Promise((resolve,reject) => {
				const xhr = new XMLHttpRequest();
				xhr.open('GET','https://api.apiopen.top/getJoke');
				xhr.send();
				xhr.onreadystatechange = function() {
					if(xhr.readyState === 4) {
						if (xhr.status >= 200 && xhr.status < 300) {
							resolve(xhr.response);
						} else {
							reject(xhr.status);
						}
					}
				}
			});
			p.then(function(val){
				console.log(val);
			},function(err){
				console.error(err);
			});
		</script>
	</body>
</html>